from http import HTTPStatus
from dashscope import Application
# 获取聊天结果
def get_chat_result(msg):
    response = Application.call(
        # 若没有配置环境变量，可用百炼API Key将下行替换为：api_key="sk-xxx"。但不建议在生产环境中直接将API Key硬编码到代码中，以减少API Key泄露风险。
        api_key='sk-f6fbbab04e904022ba8988dc39f88160',
        app_id='d4e9b9525b164ba0ae6d3a6b35886053',  # 替换为实际的应用 ID
        prompt=msg)

    if response.status_code != HTTPStatus.OK:
        print(f'request_id={response.request_id}')
        print(f'code={response.status_code}')
        print(f'message={response.message}')
        return "error"
    else:
        return  response.output.text



